package com.real8.romemp.client.mvp;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;
import com.real8.romemp.client.ClientFactory;
import com.real8.romemp.client.activity.EndTurnActivity;
import com.real8.romemp.client.activity.FeedActivity;
import com.real8.romemp.client.activity.GameStartActivity;
import com.real8.romemp.client.activity.GoodbyeActivity;
import com.real8.romemp.client.activity.HireAuxiliaActivity;
import com.real8.romemp.client.activity.LabourAllocationActivity;
import com.real8.romemp.client.activity.PiracyActivity;
import com.real8.romemp.client.activity.PoliticalActivity;
import com.real8.romemp.client.activity.ShipBuildingActivity;
import com.real8.romemp.client.activity.TradeActivity;
import com.real8.romemp.client.activity.TradeAllocationActivity;
import com.real8.romemp.client.activity.WarActivity;
import com.real8.romemp.client.place.EndTurnPlace;
import com.real8.romemp.client.place.FeedPlace;
import com.real8.romemp.client.place.GameStartPlace;
import com.real8.romemp.client.place.GoodbyePlace;
import com.real8.romemp.client.place.HireAuxiliaPlace;
import com.real8.romemp.client.place.LabourAllocationPlace;
import com.real8.romemp.client.place.PiracyPlace;
import com.real8.romemp.client.place.PoliticalPlace;
import com.real8.romemp.client.place.ShipBuildingPlace;
import com.real8.romemp.client.place.TradeAllocationPlace;
import com.real8.romemp.client.place.TradePlace;
import com.real8.romemp.client.place.WarPlace;

public class AppActivityMapper implements ActivityMapper {

	private ClientFactory clientFactory;

	/**
	 * AppActivityMapper associates each Place with its corresponding
	 * {@link Activity}
	 * 
	 * @param clientFactory
	 *            Factory to be passed to activities
	 */
	public AppActivityMapper(ClientFactory clientFactory) {
		super();
		this.clientFactory = clientFactory;
	}

	/**
	 * Map each Place to its corresponding Activity. This would be a great use
	 * for GIN.
	 */
	@Override
	public Activity getActivity(Place place) {
		// This is begging for GIN
		if (place instanceof GoodbyePlace)
			return new GoodbyeActivity((GoodbyePlace) place, clientFactory);
		else if (place instanceof GameStartPlace)
			return new GameStartActivity((GameStartPlace) place, clientFactory);
		else if (place instanceof LabourAllocationPlace)
			return new LabourAllocationActivity((LabourAllocationPlace) place,
					clientFactory);
		else if (place instanceof HireAuxiliaPlace)
			return new HireAuxiliaActivity((HireAuxiliaPlace) place,
					clientFactory);
		else if (place instanceof ShipBuildingPlace)
			return new ShipBuildingActivity((ShipBuildingPlace) place,
					clientFactory);
		else if (place instanceof TradeAllocationPlace)
			return new TradeAllocationActivity((TradeAllocationPlace) place,
					clientFactory);
		else if (place instanceof WarPlace)
			return new WarActivity((WarPlace) place, clientFactory);
		else if (place instanceof PiracyPlace)
			return new PiracyActivity((PiracyPlace) place, clientFactory);
		else if (place instanceof TradePlace)
			return new TradeActivity((TradePlace) place, clientFactory);
		else if (place instanceof FeedPlace)
			return new FeedActivity((FeedPlace) place, clientFactory);
		else if (place instanceof PoliticalPlace)
			return new PoliticalActivity((PoliticalPlace) place, clientFactory);
		else if (place instanceof EndTurnPlace)
			return new EndTurnActivity((EndTurnPlace) place, clientFactory);

		return null;
	}
}
